<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- 兼容性 -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>计划编制-项目关键节点编制及发布</title>
    <script src="/scripts/boot.js"></script>
    <style>
        html,body{
            margin:0;padding: 0;border:0;width:100%;height:100%;overflow:hidden;
        }
        body{
            background: #ffffff!important;
            padding:20px;
        }
    </style>
</head>
<body>
<div class="title-list mb-20"><span class="title-listbg"></span><span>项目计划列表</span></div>
<div id="qForm"  class="mini-toolbar1" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <div class="mb-20">
                    <!-- <span class="search-title search-ml20">项目名称</span><select id="itemId" name="itemId" class="mini-combobox w200" ajaxType="post" url="/item/list" emptyText="全部" showNullItem="true" nullItemText="全部" textField="name" valueField="id"></select>
                    --> <span class="search-title search-ml20">节点名称</span><input id = "nodeNames" name="nodeName" class="mini-textbox search-200px">
                    <span class="search-title search-ml60">选择年月</span><div id="yearItem"></div>
                    <!--<span class="search-title search-ml60">选择年月</span><input id="date1" allowInput="false" class="mini-monthpicker search-200px"/>-->
                    <a class="add-botton search-ml60" onclick="list.search()">查询</a>
                    <a class="resetting-btn search-ml20" onclick="list.reset()">重置</a>
                    <a style="margin-right: 41px;float: right;font-size: 10px;" class="resetting-btn search-ml20" onclick="list.batchfllow()">+批量关注</a>
                </div>
            </td>
        </tr>
    </table>
</div>
<!--<div class="container">
    <div class="mini-clearfix mb-10">
        <div class="mini-col-6 mini-col-sm-3">
            <a class="plan-btn mR-20"  onclick="list.addOrEdit('new')"><span class="add-bg"></span>新增</a>
        </div>
    </div>
</div>-->
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;"  url="/monthformation/keyListByPage" sizeList="[5,10,20,50]" pageSize="20"  idField="user_id" multiSelect="true" showEmptyText="true" emptyText="暂无数据" alwaysShowEmptyText="true">
        <div property="columns">
            <div type="checkcolumn" headerAlign="center" align="center" name="test"></div>
            <div type="indexcolumn" headerAlign="center" align="center">编号</div>
            <div field="remindFrequencyName" width="120" headerAlign="center" allowSort="false">计划名称</div>
            <div field="nodeName" width="120" headerAlign="center" allowSort="false">节点名称</div>
            <div field="value" width="120" headerAlign="center" align="center" allowSort="false">计划性质</div>
            <div field="beginEndDate" width="120" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">计划起止时间</div>
            <!--<div field="createDate" width="120" headerAlign="center" align="center" allowSort="false" renderer="ondayRenderer">编制时间</div>-->
            <div field="companyName" width="120" headerAlign="center" align="center" allowSort="false">责任单位</div>
            <div field="officeName" width="120" headerAlign="center" align="center" allowSort="false">责任部门</div>
            <div field="postName" width="120" headerAlign="center" align="center" allowSort="false">岗位</div>
            <div field="care" width="120" headerAlign="center" align="center">操作</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var post_flag;
    var now = new Date();
    var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
    var list = {
        //页面初始化
        init: function() {
            mini.parse();
            common.changeYears();
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.get("datagrid1").load({"yearMonth": time});
            ;
            mini.get("datagrid1").on("drawcell", function (e) {
                var column = e.column;
                var record = e.record;
                if(column.field=="beginEndDate"){
                    var dateText = "";
                    if(e.row.beginDate&&e.row.endDate){
                        dateText="至"
                    }
                    e.cellHtml = e.row.beginDate.substring(0,10)+dateText+e.row.endDate.substring(0,10);
                }
                var id = e.row.id;
                if (column.field == "care") {
                    if(record.care==0){

                        // alert(id)
                        e.cellHtml = '<a class="check-botton" onclick="list.fllow(id)" id="'+id+'">+关注</a>';
                    }else{
                        e.cellHtml = '<a class="check-botton" disabled="isDisable" onclick="list.cancelFllow(id)" id="'+id+'">-取消关注</a>';
                    }
                }
            })
        },
        fllow:function(id){
            var row = mini.get("datagrid1").getSelected();
            if (post_flag) return;
            var years = mini.get("year").getValue();
            var mouths = mini.get("month").getValue();
            var allYear = years+'-'+mouths;

            post_flag = true;
            console.log(id)
            $.ajax({
                url: ("/monthformation/follow"),
                type: "post",
                data: {
                    "id":row.id,
                    "yearMonth": allYear

                },
                success:function(data){
                    post_flag = false;
                    if(data.state){
                        // common.prompt("关注成功!");
                        mini.showTips({
                            content: '关注成功!',
                            state: 'default',
                            x: 'right',
                            y: 'center',
                            timeout: 3000
                        });
                        // $(".check-botton").attr("disabled", "true")
                        $("#"+id+"").attr("disabled", "disabled");
                        //mini.get("datagrid1").load({"yearMonth": time});
                        mini.get("datagrid1").reload();
                    }
                }
            })

        },
        batchfllow:function(){
            // var row = mini.get("datagrid1").getSelected();
            var rows=mini.get("datagrid1").getSelecteds();
            if (post_flag) return;
            /*    var years = mini.get("year").getValue();
                var mouths = mini.get("month").getValue();
                var allYear = years+'-'+mouths;*/
            var myArray=new Array();
            var arr=new Array();
            var vm;
            var vm1;
            var a ='';
            var b='';
            if (rows !="") {
                for (var i = 0; i < rows.length; i++) {
                   // post_flag = true;
                    $.ajax({
                        url: ("/monthformation/follow"),
                        type: "post",
                        data: {
                            "id": rows[i].id

                        },
                        success: function (data) {
                           post_flag = false;
                            // common.prompt("批量关注成功!");
                            myArray.push(data.state);
                            arr.push(data.message);

                            for(var i=0;i<myArray.length;i++){
                                if(myArray[i]==false){
                                    a = JSON.stringify(myArray);
                                }else if( myArray[i]==true){
                                    a = JSON.stringify(myArray);
                                  /* */
                                    mini.get("datagrid1").reload();
                                }
                            }
                            arr.push(a);
                            if(i==rows.length){
                            vm = a.indexOf(false);
                            vm1 = a.indexOf(true);
                               if(vm1>-1){
                                mini.showTips({
                                    content: '批量关注成功!',
                                    state: 'default',
                                    x: 'right',
                                    y: 'center',
                                    timeout: 3000
                                });
                                return;
                                mini.get("datagrid1").reload();
                            }else if(vm==1 && vm1==-1){
                                mini.showTips({
                                    content: '已经批量关注成功!',
                                    state: 'default',
                                    x: 'right',
                                    y: 'center',
                                    timeout: 3000
                                });
                                mini.get("datagrid1").reload();
                            }

                        }
                        }
                    })
                }
            }else{
                alert("请选中一条记录");
            }

        },
        cancelFllow:function(id){
            var row = mini.get("datagrid1").getSelected();
            if (post_flag) return;
            $.ajax({
                url: ("/monthformation/cancelFollow"),
                type: "post",
                data: {
                    "planNodeId":row.id
                },
                success:function(data){
                    post_flag = false;
                    if(data.state){
                        // common.prompt("取消关注成功!");
                        mini.showTips({
                            content: '取消关注成功!',
                            state: 'default',
                            x: 'right',
                            y: 'center',
                            timeout: 3000
                        });
                        //mini.get("datagrid1").load({"yearMonth": time});
                        $("#"+id+"").attr("disabled", "disabled");
                        mini.get("datagrid1").reload();
                    }
                }
            })
        },
        //    新增或编辑
        addOrEdit: function (opt) {
            mini.open({
                url: "/planning/monthlyPlan/new.html",
                title: (opt=="edit"?"编辑":"新增")+"项目信息", width: 1100, height: 300,
                onload: function () {
                    if(opt=="edit"){
                        var row = mini.get("datagrid1").getSelected();
                        var data = {"id": row.id,"state":opt};
                    }else{
                        var data = {"state":opt};
                    }
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.view.SetData(data);
                },
                ondestroy: function (action) {
                    mini.get("datagrid1").reload();
                }
            });
        },
        //    查看
        view: function(){
            var row = mini.get("datagrid1").getSelected();
            if (row) {
                mini.open({
                    url: "/planning/keyPoint/view.html",
                    title: "项目信息", width: 1100, height: 700,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {"id": row.id};
                        iframe.contentWindow.view.SetData(data);
                    },
                    ondestroy: function (action) {
                        mini.get("datagrid1").reload();
                    }
                });

            } else {
                alert("请选中一条记录");
            }
        },
        //    查询
        search: function () {
            var years = mini.get("year").getValue();
            var mouths = mini.get("month").getValue();
            var allYear = years+'-'+mouths;
            var data = {
                "nodeName": mini.get("nodeNames").getValue(),
                "yearMonth": allYear
            };
            mini.get("datagrid1").load(data);
        },
        //重置
        reset:function(){
            mini.get("year").setValue(new Date().getFullYear());
            var years = mini.get("year").getValue();
            var endMonth = new Date().getMonth()+1;
            mini.get("month").setValue(endMonth);
            mini.get("nodeNames").setValue("");
            var now = new Date();
            var time = now.getFullYear() + "-" +((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1);
            mini.get("datagrid1").load({"yearMonth": time});
            //mini.get("datagrid1").reload();
        },
        //    删除
        remove: function () {
            var row = mini.get("datagrid1").getSelected();
            if (row) {
                mini.confirm("确定删除选中记录？","确定",function (action) {
                    if(action=="ok"){
                        $.ajax({
                            url: "/messageRemind/del",
                            type : "post",
                            data:{"id":row.id},
                            success: function (text) {
                                if (text.state) {
                                    mini.get("datagrid1").reload();
                                } else {
                                    mini.showMessageBox({
                                        showModal: false,
                                        width: 250,
                                        title: "提示",
                                        iconCls: "mini-messagebox-warning",
                                        message: text.message,
                                    });

                                }
                            }
                        });
                    }
                });
            } else {
                alert("请选中一条记录");
            }
        }
    };
    list.init();
</script>
</body>
</html>